<?php
include('image_upload.inc');
require 'ShopDAO.inc';
if (isset($_REQUEST['scan']))
{
	$adId = trim($_POST['adId']);
	$shopId = trim($_POST['shopId']);
	$image = trim($_POST['image']);

	$isSuccess;

 	$type=$_FILES['file']['type'];
    if($type!="image/pjpeg" && $type!="image/jpeg" && $type!="image/gif" && $type!="image/png")//文件类型不在指定范围
    {
  		if ($shopId != "")
		$query = "UPDATE advertising SET shop_id=".$shopId." WHERE ad_id=".$adId;	
    }

	else
	{
		// 声明一个上传类
		$upfos = new image_upload('file', 'advertising');

		/**
		 * 建议使用随机生成的文件名，以避免上传重名的文件。
		 * 例如： $upfos->upload ( $upfos->newName());
		 */
		// 上传文件
		$isSuccess = $upfos->upload($upfos->newName());

		$uploadedimage = $upfos->filePath();
		$shop = new shop();
		$query = "";
		if ($isSuccess) {
			//删除之前图片
			unlink($image);
			if ($shopId == "") {
				$query = "UPDATE advertising SET image='$uploadedimage' WHERE ad_id=".$adId;
			}
			else
			{
				$query = "UPDATE advertising SET image='$uploadedimage',shop_id=".$shopId." WHERE ad_id=".$adId;
					
			}
		}
	}
	
	mysql_query($query);
	echo "修改广告成功！<hr><p>";
	echo "<br><a href='showAdvertising.php'>查看广告</a>";
}
?>